package com.kaifamiao.service.Impl;

import com.kaifamiao.mapper.AdminMapper;
import com.kaifamiao.model.AdminModel;
import com.kaifamiao.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service()
@Transactional(propagation = Propagation.REQUIRED)
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminMapper mapper;
    @Override
    public AdminModel findByAdminId(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateAdmin(AdminModel model) {
        Long id=model.getId();
        String adminName=model.getAdminname();
        String password=model.getPassword();
        String realName=model.getRealname();
        String sex=model.getSex();
        String tel=model.getTel();
        Integer roleId=model.getRoleid();
        model.setId(id);
        model.setAdminname(adminName);
        model.setPassword(password);
        model.setRealname(realName);
        model.setSex(sex);
        model.setTel(tel);
        model.setRoleid(roleId);
        return mapper.updateByPrimaryKeySelective(model);
    }

    @Override
    public List<AdminModel> findByAdmin(AdminModel model) {
        String adminName=model.getAdminname();
        String password=model.getPassword();
        model.setAdminname(adminName);
        model.setPassword(password);
        return mapper.selectByAdmin(model);
    }

    @Override
    public AdminModel findByAdminName(String adminName) {
        return mapper.selectByAdminName(adminName);
    }
}
